$("#hearder").on("click","img",function(){
	history.go(-1)
})

var page=1;
getData(1,page)
$("#main").on("click",".order-title-btn",function(){
	$(this).addClass("thison").siblings("span").removeClass("thison");
	var id=$(this).attr('_attr');
	getData(id,1)
	})

$("#main").on("click", ".search-txt_s", function () {
        var type = $(".select").val();
        var keyword = $(".search-inp").val();
        $(".search-inp").val("");
		window.location.href="search_result.html?type="+type+"&keyword="+keyword;
    })
$("#main").on("input", ".search-inp", function () {
        var val = $(this).val();
        if (val) {
            $(".search-img").css("display", "block");
            $(".search-txt_cancel").css("display", "none")
            $(".search-txt_s").css("display", "block")
        } else {
            $(".search-img").css("display", "none");
            $(".search-txt_s").css("display", "none")
            $(".search-txt_cancel").css("display", "block")
        }
    })
$("#main").on("click",".search-img",function(){
	$(".search-img").css("display", "none");
    $(".search-inp").val("")
    $(".search-txt_cancel").css("display", "block")
    $(".search-txt_s").css("display", "none")
})
 $("#main").on("click",".op-remind",function(){
    $(".op-remind").hide()
    $(".op-remind-out").show()
})
function getData(id,page){
		$.ajax({
    	type:"get",
    	url:Url+"adminOrder/" + id + "/page/" + page,
    	async:false,
    	beforeSend: function () {
    		showDiv()
		},
    	success: function(data){
           hiddenDiv()	
           if(data.pagingData.length==0&&data.counts!=0){
           	 taostr("没有更多了",1000)
           }
           if(data.counts==0){
           		$(".discount-main-no").show()
           }else{
           		$(".discount-main-no").hide()
           }
           console.log(data);
           var str='';
           if(id==9){           	
           	 for(var i=0;i<data.pagingData.length;i++){
           	 	var timer='';          	 
           	 	if(data.pagingData[i].update_time!=""){
           	 		timer=timestampToTime(data.pagingData[i].update_time)
           	 	}else{
           	 		timer=timestampToTime(data.pagingData[i].createtime)
           	 	}
           	 	str+='<div class="order-main">'   
					    	+'<a href="orderDetails.html?id='+data.pagingData[i].order_id+'">'
					    		+'<div class="order-num clear">'
					    			+'<span class="order-num-l">订单编号：'+data.pagingData[i].order_number+'</span>'
					    			+'<span  class="order-num-r">用户名称：'+data.pagingData[i].nickname+'</span>'
					    		+'</div>'
						        +'<div class="order-num clear">'
						        	+'<span class="order-num-l">产品信息：'+data.pagingData[i].snap_name+'</span>'
						        	+'<span  class="order-num-r">最近提醒时间：'+timer+'</span>'
						        +'</div>'
						        +'<div class="order-price clear">'
						            +'<div class="op-price">提醒次数：'+data.pagingData[i].num+'</div>'	           
						            +'<a href="chat.html?id='+data.pagingData[i].user_id+'" class="op-ready">联系客户</a>'					           
						        +'</div>'
					    	+'</a>'			        
					    +'</div>'	
           	 }           	 
           }else{
           	for(var i=0;i<data.pagingData.length;i++){
           		var msg='';
           		var str1='';
           		        if (data.pagingData[i].order_states == 1) {
                            msg = '待付款';
                            if(data.pagingData[i].recording==null){
                        		str1= '<div class="op-remind">提醒客户付款</div>';
                        	}else{
                        		str1= '<div class="op-remind-out">提醒客户付款</div>';
                        	}
                            
                        } else if (data.pagingData[i].order_states == 2) {
                            msg = '待发货';
                            
                        } else if (data.pagingData[i].order_states == 3) {
                            msg = '已发货';
                           	str1= '<a href="logisticsInformation.html?id='+data.pagingData[i].order_id+'" class="op-remind">查看物流</a>';
                        }
                        else if (data.pagingData[i].order_states == 5) {
                            msg = '已取消';                           
                        }
                        else if (data.pagingData[i].order_states == 6) {
                            msg = '待评价';
                            str1= '<a href="logisticsInformation.html?id='+data.pagingData[i].order_id+'" class="op-remind">查看物流</a>';
                            
                        } else if (data.pagingData[i].order_states == 7) {
                            msg = '已完成';
                            str1= '<a href="logisticsInformation.html?id='+data.pagingData[i].order_id+'" class="op-remind">查看物流</a>';
                        }                      
		        str+='<div class="order-main">'   
				    	+'<a href="orderDetails.html?id='+data.pagingData[i].order_id+'">'
				    		+'<div class="order-num clear"><span class="order-num-l">订单编号：'+data.pagingData[i].order_number+'</span><span  class="order-num-r">订单状态：'+msg+'</span></div>'
					        +'<div class="order-num clear"><span class="order-num-l">订单时间：'+timestampToTime(data.pagingData[i].createtime)+'</span><span  class="order-num-r">用户名称：'+data.pagingData[i].nickname+'</span></div>'
					        +'<div class="order-details clear">'
					            +'<img class="od-img" src="'+data.pagingData[i].snap_img+'"></img>'
					            +'<div class="od-mian" >'
					                +'<span>'+data.pagingData[i].snap_name+'</span>'
					            +'</div>'
					            +'<div class="od-state" >'
					                +'<span>×'+data.pagingData[i].total_count+'</span>'
					            +'</div>'
					        +'</div>'
					        +'<div class="order-price clear">'
					            +'<div class="op-price">合计：'+data.pagingData[i].total_price+'</div>'	            
					            +'<a href="chat.html?id='+data.pagingData[i].user_id+'" class="op-ready">联系客户</a>'	
					            +str1
					        +'</div>'
				    	+'</a>'			        
				    +'</div>'
			    }
           }
         if(page==1){
         	$("#order-main-list").html(str)
         }else{
         	$("#order-main-list").append(str)
         }
		
        },
    	complete: function () {
			
		}	
    });
}

slideDown("#order-main-list", 0, function (e) {
	var that = this;
	var obj=$(".order-title-btn");
	var id;
	for(var i=0;i<obj.length;i++){
		if(obj.eq(i).hasClass("thison")){
			id=obj.eq(i).attr("_attr")
		}
		
	}
    getData(id,1)
    that.back.call();

});
slideUp("#order-main-list", 0, function (e) {

    var that = this;
    var obj=$(".order-title-btn");
	var id;
	for(var i=0;i<obj.length;i++){
		if(obj.eq(i).hasClass("thison")){
			id=obj.eq(i).attr("_attr")
		}
	}
    page++;
    getData(id,page)
    that.backup.call();
});
$("#main").on("click",".op-ready",function(){
	var kefu=JSON.parse(storage.getItem("userinfo"));
	if(kefu.user_id==null){
		taostr("此账号暂未开通客服功能！",1000);
		return false;
	}
})
$(".order-title-8").click(function(){
	location.href="refund.html"
})
